import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class InitialRamLoadingModel {

	private static Map<Integer, byte[]> byteMap = new LinkedHashMap<Integer, byte[]>();
	private static List<Integer> searchList = new ArrayList<Integer>();
	private static Map<Integer, byte[]> tempMap = new LinkedHashMap<Integer, byte[]>();

	private FileInputStream fis = null;
	private FileChannel fc = null;
	private ByteBuffer byteBuf = null;

	private int readChannel() throws IOException {
		byte b;
		int byteBufSize = 32;
		byte[] word = new byte[byteBufSize];
		byte[] key = null;
		byte[] value = null;
		int byteBufCount = 0;

		int bytesRead = fc.read(byteBuf);
		byteBuf.flip();
		while (byteBuf.hasRemaining()) {
			b = byteBuf.get();
			if (b == 44) {
				key = word;
				byteMap.put(Arrays.hashCode(key), key);
				word = new byte[byteBufSize];
				byteBufCount = 0;
				continue;
			} else if (b == 13 || b == 10) {
				if (byteBufCount == 0) {
					continue;
				}
				value = word;
				word = new byte[byteBufSize];
				byteMap.put(Arrays.hashCode(value), value);
				byteBufCount = 0;
				continue;
			}
			word[byteBufCount++] = b;
		}
		byteBuf.clear();
		return bytesRead;
	}

	private int findValues() {
		int count = 0;
		Collection<Integer> tempIdColln = new ArrayList<Integer>(searchList);
		Set<Integer> idValueSet= tempMap.keySet();
		tempIdColln.removeAll(idValueSet);
		
		for (Map.Entry<Integer, byte[]> entry : byteMap.entrySet()) {
			for (Iterator<Integer> itr = tempIdColln.iterator(); itr.hasNext();) {
				Integer ids = itr.next();
				if (ids.intValue() ==  entry.getKey().intValue()) {
					count++;
					tempMap.put(ids, entry.getValue());
					itr.remove();
				}
			}
		}
		return count;
	}

	private void openConnection(String fileName) throws FileNotFoundException {

		this.fis = new FileInputStream(new File(fileName));
		this.fc = fis.getChannel();
		this.byteBuf = ByteBuffer.allocate(1024 * 66);

	}

	private void closeConnection() {
		try {
			if (fis != null) {
				fis.close();
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static boolean contentEquals(byte[] id1, byte[] id2) {

		return Arrays.equals(id1, id2);

	}

	public static void main(String[] args) {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		char[] cbuf;

		// This is just a demo. You can use any logic here to read from stdin -
		// till End of File or End of Stream etc.,
		cbuf = new char[1024];
		try {
			in.read(cbuf);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		String inputs = new String(cbuf);
		args = inputs.split(" ");
		if (args == null) {
			System.out.print("FAILURE");
			System.exit(1);
		}
		InitialRamLoadingModel m = new InitialRamLoadingModel();

		if (args.length == 1) {
			File f = new File(args[0].trim());
			if (f.exists()) {
				int bytesRead = 0;
				try {
					m.openConnection(args[0].trim());
					while (bytesRead != -1) {
						bytesRead = m.readChannel();
					}
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				} finally {
					m.closeConnection();
				}
				System.out.print("READY");
				System.exit(0);
			} else {
				System.out.print("FAILURE");
				System.exit(1);
			}
		}

		for (int i = 1; i < args.length; i++) {
			String arg = args[i].trim();
			if (arg.contains("T=") || arg.contains("R=")) {
				String ids = arg.substring(arg.indexOf("=") + 1);
				String[] idArr = ids.split(",");
				for (int j = 0; j < idArr.length; j++) {
					searchList.add(Arrays.hashCode(idArr[j].trim().getBytes()));
				}
			}
		}
		int bytesRead = 0;
		try {
			m.openConnection(args[0].trim());
			int count = 0;
			bytesRead = m.readChannel();
			while (bytesRead != -1) {
				count+=m.findValues();
				if(count == searchList.size()){
					break;
				}
				bytesRead = m.readChannel();
			}
			String value = "";
			byte[] byteArrVal= null;
			for (int i = 0; i < searchList.size(); i++) {
				byteArrVal = tempMap.get(searchList.get(i));
				if(byteArrVal == null){
					value = "FAILURE";
				}	else	{
					value = new String(byteArrVal);
				}
				System.out.print(value);
				if((i +1) < searchList.size())	{
					System.out.print(",");
				}				
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			m.closeConnection();
		}
	}
}
// C:\\sivravis\\dev\\studies\\BOC2014\\codeContest1M.csv
// C:\sivravis\dev\studies\BOC2014\codeContest1M.csv
// C:\\sivravis\\dev\\studies\\BOC2014\\sampleInput.csv T=TXN00000000000000043179168899325,TXN00000000000000050209776656593 R=REF00000000000000116009591331268
// C:\\sivravis\\dev\\studies\\BOC2014\\codeContest1M.csv T=TXN00000000000000038017647990705,TXN00000000000000187337910501133 R=REF00000000000000269582048411792,REF00000000000000242906007369522
// C:\\sivravis\\dev\\studies\\BOC2014\\codeContest10M.csv T=TXN00000000000000038017647990705,TXN00000000000000187337910501133 R=REF00000000000000269582048411792,REF00000000000000242906007369522
// System.out.println(count++ + " times read " + bytesRead + " Bytes.");
//E:\\doc\\contest\\comviva\\codeContest1M.csv\\codeContest1M.csv T=TXN00000000000000038017647990705,TXN00000000000000187337910501133 R=REF00000000000000269582048411792,REF00000000000000242906007369522